package com.carskeeper.common.exception;

import com.carskeeper.common.dtos.AppHttpCodeEnum;
import com.carskeeper.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
@Slf4j
public class BasicExceptionHandler {
    /**
     * 处理其他异常
     */
    @ExceptionHandler(Exception.class) //指定需要处理的异常类型
    public ResponseResult exception(Exception e) {
        log.info("系统异常",e);
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR.getCode(), AppHttpCodeEnum.SERVER_ERROR.getErrorMessage());
    }

    /**
     * 处理NcException
     */
    @ExceptionHandler(AcException.class)
    public ResponseResult NcException(AcException ncException) {
        log.error("业务异常",ncException);
        return ResponseResult.errorResult(ncException.getCode(), ncException.getMessage());
    }
}
